<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <h1>字符串替换</h1>
    <div>
        <!-- <span style="color:red">ab</span>cjfhdjdfh<span style="color:red">AB</span> -->
      </div>
</head>
<script>
    var str='abcjfhdjgabdfdfhAB'
    var target = "ab"
    var reg=new RegExp(target,'gi')// g全局匹配和i不区分大小写
    // var m ='<span style="color:red">' + target + '</span>'
    // s是正则匹配的结果
    var str=str.replace(reg,(s)=>{
        console.log(s);
        return '<span style="color:red">' + s + '</span>'
    })
    console.log(str);
</script>
<body>
    
</body>
</html>